package com.listeningframework.boot.commons.httpclient;

import org.apache.http.HttpEntity;

/**
 * HttpClient Utils
 *
 * @author Listening
 * @version $Id: HttpClientUtils.java, v 0.1 2016年8月6日 上午11:54:26 Listening Exp $
 */
public final class HttpClientUtils {
    /**
     * HttpClient Factory
     */
    private static final HttpClientFactory FACTORY = HttpClientFactory.newInstance();

    private HttpClientUtils() {

    }

    public static HttpClientFactory getClient() {
        return FACTORY;
    }

    /**
     * Get方法查询
     *
     * @param address 请求地址
     * @return String
     * @throws Exception 异常
     */
    public static String getMethodGetContent(String address) throws Exception {
        return FACTORY.getContent(address);
    }

    /**
     * Post方法查询
     *
     * @param address     请求地址
     * @param paramEntity 请求参数
     * @return String
     * @throws Exception 异常
     */
    public static String getMethodPostContent(String address, HttpEntity paramEntity) throws Exception {
        return FACTORY.postContent(address, paramEntity);
    }

    /**
     * HttpClient get方法请求返回Entity
     *
     * @param address 请求地址
     * @return byte[]
     * @throws Exception 异常
     */
    public static byte[] getMethodGetBytes(String address) throws Exception {
        return FACTORY.getBytes(address);
    }

    /**
     * Post Entity
     *
     * @param address     请求地址
     * @param paramEntity 请求参数
     * @return byte[]
     * @throws Exception 异常
     */
    public static byte[] getMethodPostBytes(String address, HttpEntity paramEntity) throws Exception {
        return FACTORY.postBytes(address, paramEntity);
    }

}
